package com.woniuxy.carrental.controller;

import com.woniuxy.carrental.entity.Details;
import com.woniuxy.carrental.entity.PageBean;
import com.woniuxy.carrental.entity.Purchase;
import com.woniuxy.carrental.entity.ResponseResult;
import com.woniuxy.carrental.service.DetailsService;
import com.woniuxy.carrental.service.PurchaseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author author
 * @create 2021-10-08 10:40
 * 肖某的仓库表单控制器
 */
@CrossOrigin  //解决跨域
@RestController  //要求返回json格式数据异步使用
public class DetailsController {
    @Resource
    DetailsService detailsService;

    @Resource
    PurchaseService purchaseService;
    //入库
    @RequestMapping("/add/{purchase_id}")
   public List<Purchase> addDetais(@PathVariable("purchase_id") String purchase_id){
        List<Purchase> purchases = detailsService.insertDe(purchase_id);
        System.out.println(purchase_id);
        return purchases;
   }

   //点击超链接展示所有的可以入库的采购订单purchase
//    @RequestMapping("/selectAll")
//    public ResponseResult<PageBean<Purchase>> select(){
//        List<Purchase> purchases = purchaseService.selectAllByTrue();
//        PageBean<Purchase> pageBean =new PageBean<>();
//        return new ResponseResult<PageBean<Purchase>>(pageBean,200,"OK");
//    }
    @RequestMapping("/selectAllL123")
    public List<Purchase> selectALL(){

        System.out.println("来了没有");
        List<Purchase> purchases = purchaseService.selectAllByTrue();
       return purchases;
    }

    //分页查询表中所有数据
@RequestMapping("/selectAllByPage")
    public ResponseResult<PageBean<Details>> selectAllByPageBean(Details details,
                                                                 int pageSize, int pageIndex){
        return detailsService.selectDetailsByPageService(details, pageIndex, pageSize);

}

//查询表中所有数据
    @GetMapping("/selectAllDetails")
    public List<Details> selectAllDetailsController(){
        return detailsService.selectAllService();
    }
}
